//
//  NoticeView.m
//  UEAssistant
//
//  Created by mac on 2017/2/13.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "NoticeView.h"
#define ORC_RADIUS 8

@implementation NoticeView
@synthesize title;

-(id) init:(CGPoint) p str:(NSString*) str
{
    if([super init] == nil)
        return nil;
    path = [[UIBezierPath alloc] init];
    label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    label.textAlignment = NSTextAlignmentCenter;
    [label setBackgroundColor: [UIColor clearColor]];
    font = [UIFont systemFontOfSize:12.0];
    label.font = font;
    [self setBackgroundColor: [UIColor clearColor]];
    [self setAlpha:0.8];
    [self addSubview: label];
    [self set_point: p];
    [self set_title: str];
    return (self);
}
-(void)reloadData
{
    [self setNeedsDisplay];
}

-(void)set_point:(CGPoint)p
{
    point = p;
}

- (void)drawRect:(CGRect)rect {
    [[UIColor colorWithWhite:0.85 alpha:1] setFill];
    [path fill];
}
-(void) set_title:(NSString*) str
{
    label.text = str;
    size = CGSizeMake(70, 20);
    label.frame = CGRectMake(0, 0, size.width, size.height);
    size.height += 30;
    size.width += 60;
    double x = point.x - size.width;
    double y = point.y - size.height/2;
    origin.x = x;
    origin.y = y;
    self.frame = CGRectMake(origin.x, origin.y, size.width-30, size.height-10);
    [self set_path];
}

-(void)set_path
{
    NSLog(@"bounds %@", NSStringFromCGRect(self.bounds));
    NSLog(@"size %@", NSStringFromCGSize(size));
    double h = size.height - ORC_RADIUS*3;
    CGPoint p = CGPointMake(10, 10);
    NSLog(@"1 start point %@", NSStringFromCGPoint(p));
    [path moveToPoint:p];
    p.x += size.width/2-ORC_RADIUS*3-3;
    NSLog(@"2 middle point %@", NSStringFromCGPoint(p));
    [path addLineToPoint: p];
    p.y-=4;
    p.x+=4;
    NSLog(@"2 middle point %@", NSStringFromCGPoint(p));
    [path addLineToPoint: p];
    p.y+=4;
    p.x+=4;
    NSLog(@"3 middle point %@", NSStringFromCGPoint(p));
    [path addLineToPoint: p];
    p.x += size.width/2;
    NSLog(@"4 middle point %@", NSStringFromCGPoint(p));
    [path addLineToPoint: p];
    NSLog(@"5 middle point %@", NSStringFromCGPoint(p));
    p.y += h;
    [path addLineToPoint: p];
    p.x -= size.width;
    NSLog(@"6 middle point %@", NSStringFromCGPoint(p));
    [path addLineToPoint: p];
    p.y -=h;
    [path addLineToPoint: p];
    NSLog(@"7 middle point %@", NSStringFromCGPoint(p));
    [path closePath];
}

@end
